<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('修改FTP内生性调整型参数配置')"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-config-edit" th:object="${ftpDepositLoanAdjustmentConfig}">
        <input name="configId" th:field="*{configId}" type="hidden">

        <div class="form-group">
            <label class="col-sm-3 control-label is-required">FTP频率类型:</label>
            <div class="col-sm-8">
                <select id="frequencyType" name="frequencyType" class="form-control m-b" th:with="type=${@dict.getType('ftp_frequency_type')}"
                        required onchange="changeFrequencyType(this)" >
                    <option value="">请选择</option>
                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{frequencyType}"></option>
                </select>
            </div>
        </div>


        <div class="form-group">
            <label class="col-sm-3 control-label is-required">FTP频率子类型:</label>
            <div class="col-sm-8">
                <select id="frequencySubType" name="frequencySubType" class="form-control m-b"
                        required onchange="changeFrequencySubType(this)" >
                    <option value="">所有</option>
                    <option th:text="*{frequencySubType}" th:value="*{frequencySubType}"  th:field="*{frequencySubType}"></option>
                </select>
            </div>

        </div>


        <div class="form-group">
            <label class="col-sm-3 control-label is-required">原始期限:</label>
            <div class="col-sm-8">
                <select id="originalDeadlineType" name="originalDeadlineType" class="form-control m-b" required>
                    <option th:text="*{originalDeadlineType}" th:value="*{originalDeadlineType}"  th:field="*{originalDeadlineType}"></option>
                </select>
            </div>

        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">周期计算单位类型:</label>
            <div class="col-sm-8">
                <select id="calcuPeriodUnit" name="calcuPeriodUnit" class="form-control m-b" th:with="type=${@dict.getType('calcu_period_unit_type')}"
                        required>
                    <option value="">请选择</option>
                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{calcuPeriodUnit}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">下限天数:</label>
            <div class="col-sm-8">
                <input name="calcuUnderDay" class="form-control" type="text" required th:field="*{calcuUnderDay}">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">上限天数:</label>
            <div class="col-sm-8">
                <input name="calcuUpperDay" class="form-control" type="text" required th:field="*{calcuUpperDay}">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">调整值:</label>
            <div class="col-sm-8">
                <input name="adjustmentRate" class="form-control" type="text" required th:field="*{adjustmentRate}">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">备注:</label>
            <div class="col-sm-8">
                <input name="remark" class="form-control" type="text" th:field="*{remark}">
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">

    var prefix = ctx + "ecard/ftp/adjustment/config";

    $("#form-config-edit").validate({
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/edit", $('#form-config-edit').serialize());
        }
    }


    $(document).ready(function () {

        var frequencyTypeVal = $('#frequencyType').val();
        var frequencySubType = $('#frequencySubType').val();
        changeFrequencyInfoInit(frequencyTypeVal,frequencySubType)
    });

    function changeFrequencyInfoInit(frequencyTypeVal,frequencySubType) {
        changeFrequencyTypeInit(frequencyTypeVal,frequencySubType);
        changeFrequencySubTypeInit(frequencyTypeVal,frequencySubType);
    }

    function changeFrequencyTypeInit(frequencyTypeVal,frequencySubType){
        var prefix = ctx + "system/dict/info";
        $.ajax({
            type: "GET",
            url: prefix + "/getDictDataByDictType?dictType=" + frequencyTypeVal,
            async:false,
            success: function (data) {
                if (data != null && data.length > 0) {
                    $('#frequencySubType').html('');
                    var frequencySubTypeStr = '<option value="">所有</option>';
                    for (var i = 0; i < data.length; i++) {

                        if(data[i].dictValue == frequencySubType){
                            frequencySubTypeStr += "<option value='" + data[i].dictValue + "' selected='selected'>" + data[i].dictLabel + "</option>";
                        }else{
                            frequencySubTypeStr += "<option value='" + data[i].dictValue + "'>" + data[i].dictLabel + "</option>";
                        }
                    }
                    $('#frequencySubType').html(frequencySubTypeStr);
                } else {
                    $('#frequencySubType').html(frequencySubTypeStr);
                }
            }
        });

    }

    function changeFrequencySubTypeInit(frequencyTypeVal,frequencySubType){

        var prefix = ctx + "system/dict/info";

        var originalDeadlineTypeVal = $('#originalDeadlineType').val();

        $.ajax({
            type: "GET",
            url: prefix + "/getDictDataByDictType?dictType=" + frequencyTypeVal + '_' + frequencySubType + 'M',
            async:false,
            success: function (data) {
                if (data != null && data.length > 0) {
                    $('#originalDeadlineType').html('');
                    var originalDeadlineTypeStr = '<option value="">所有</option>';
                    for (var i = 0; i < data.length; i++) {

                        if(data[i].dictValue == originalDeadlineTypeVal){
                            originalDeadlineTypeStr += "<option value='" + data[i].dictValue + "' selected='selected'>" + data[i].dictLabel + "</option>";
                        }else{
                            originalDeadlineTypeStr += "<option value='" + data[i].dictValue + "'>" + data[i].dictLabel + "</option>";
                        }
                    }
                    $('#originalDeadlineType').html(originalDeadlineTypeStr);
                } else {
                    $('#originalDeadlineType').html(originalDeadlineTypeStr);
                }

            }
        });



        var prefix = ctx + "system/dict/info";
        $.ajax({
            type: "GET",
            url: prefix + "/getDictDataByDictType?dictType=" + frequencyTypeVal + '_' + $(e).val() + 'M',
            success: function (data) {
                if (data != null && data.length > 0) {
                    $('#originalDeadlineType option').not(":first").remove();
                    for (var i = 0; i < data.length; i++) {
                        $("<option value='" + data[i].dictValue + "'>" + data[i].dictLabel + "</option>").appendTo("#originalDeadlineType");
                    }
                } else {
                    $('#originalDeadlineType option').not(":first").remove();
                }
            }
        });


    }


    function changeFrequencyType(e) {

        var prefix = ctx + "system/dict/info";
        $.ajax({
            type: "GET",
            url: prefix + "/getDictDataByDictType?dictType=" + $(e).val(),
            success: function (data) {
                if (data != null && data.length > 0) {
                    $('#frequencySubType option').not(":first").remove();
                    for (var i = 0; i < data.length; i++) {
                        $("<option value='" + data[i].dictValue + "'>" + data[i].dictLabel + "</option>").appendTo("#frequencySubType");
                    }
                } else {
                    $('#frequencySubType option').not(":first").remove();
                }
            }
        });
    }



    function changeFrequencySubType(e) {

        var frequencyTypeVal = $(frequencyType).val();
        // alert(frequencyTypeVal + '_' + $(e).val() + 'M');

        var prefix = ctx + "system/dict/info";
        $.ajax({
            type: "GET",
            url: prefix + "/getDictDataByDictType?dictType=" + frequencyTypeVal + '_' + $(e).val() + 'M',
            success: function (data) {
                if (data != null && data.length > 0) {
                    $('#originalDeadlineType option').not(":first").remove();
                    for (var i = 0; i < data.length; i++) {
                        $("<option value='" + data[i].dictValue + "'>" + data[i].dictLabel + "</option>").appendTo("#originalDeadlineType");
                    }
                } else {
                    $('#originalDeadlineType option').not(":first").remove();
                }
            }
        });
    }


</script>
</body>
</html>